
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';


class ThemeService extends GetxService {

  final _getStorage = GetStorage();
  final _key = 'currentThemeIndex';

  // 所有可用主题
  final List<ThemeData> _themes = [
    AppThemes.blueTheme,
    AppThemes.pinkTheme,
    AppThemes.greenTheme,
    AppThemes.darkTheme,
  ];

  // 获取当前主题索引
  int get currentThemeIndex => _getStorage.read(_key) ?? 0;

  // 获取当前主题
  ThemeData get currentTheme => _themes[currentThemeIndex];

  // 切换主题
  void changeTheme(int index) {
    if (index >= 0 && index < _themes.length) {
      _getStorage.write(_key, index); // 保存索引
      Get.changeTheme(_themes[index]); // 切换主题
    }
  }

  // 切换到下一个主题（循环切换）
  void nextTheme() {
    final nextIndex = (currentThemeIndex + 1) % _themes.length;
    changeTheme(nextIndex);
  }
}

class AppThemes{

  // 蓝色主题
  static final blueTheme = ThemeData(
    primarySwatch: Colors.blue,
    brightness: Brightness.light,
    scaffoldBackgroundColor: Colors.blue[50],
    appBarTheme: AppBarTheme(color: Colors.blue[600]),
  );

  // 粉色主题
  static final pinkTheme = ThemeData(
    primarySwatch: Colors.pink,
    brightness: Brightness.light,
    scaffoldBackgroundColor: Colors.pink[50],
    appBarTheme: AppBarTheme(color: Colors.pink[600]),
  );

  // 绿色主题
  static final greenTheme = ThemeData(
    primarySwatch: Colors.green,
    brightness: Brightness.light,
    scaffoldBackgroundColor: Colors.green[50],
    appBarTheme: AppBarTheme(color: Colors.green[600]),
  );

  // 暗色主题（可选）
  static final darkTheme = ThemeData(
    primarySwatch: Colors.grey,
    brightness: Brightness.dark,
  );

}

class SomeTheme extends ThemeExtension<SomeTheme>{

  @override
  ThemeExtension<SomeTheme> copyWith() {
    // TODO: implement copyWith
    throw UnimplementedError();
  }

  @override
  ThemeExtension<SomeTheme> lerp(covariant ThemeExtension<SomeTheme>? other, double t) {
    // TODO: implement lerp
    throw UnimplementedError();
  }
}

Widget a= Container();